package org.emcode.sample.appleguice.shared.entity;

public abstract class AbstractPersistentEntity implements PersistentEntityInterface {

    protected Long id;
    private Integer version;

    public Long getId()
    {
        return this.id;
    }

    public void setId(final Long id)
    {
        this.id = id;
    }

    public Integer getVersion() {
        return this.version;
    }

    public void setVersion(final Integer version) {
        this.version = version;
    }

    @Override
        public boolean equals(final Object o) {
        if (this == o) {
                        return true;
                }
        if ((o == null) ||
            !(o instanceof PersistentEntityInterface)) {

            return false;
        }

        final PersistentEntityInterface other
            = (PersistentEntityInterface)o;

        // if the id is missing, return false
        if (this.id == null) {
                        return false;
                }

        // equivalence by id
        return this.id.equals(other.getId());
    }

    @Override
        public int hashCode() {
        if (this.id != null) {
            return this.id.hashCode();
        } else {
            return super.hashCode();
        }
    }

    @Override
        public String toString() {
        String str = ""+
        "[id=" + this.id + "]" +
        "[version=" + this.version + "]";
       return str;
    }

}

